package com.MusicWeb.service;

import com.MusicWeb.dao.DB;

import java.util.List;
import java.util.Map;

public class CollectionService {
    /*
    收藏音乐  传音乐id 与用户的id
     */
    public int CollectionAdd(Integer music_id, Integer user_id) {
        try {
            List<Map<String, Object>> res=DB.executeQuery("select * from usermusic where music_id= ? and user_id= ?"
                    ,music_id
                    ,user_id);

            if (res.size()==1){
                return -1;
            }
            int a = DB.executeUpdate
                    ("INSERT INTO `usermusic`(`music_id`, `user_id`) VALUES ( ? , ? )", music_id, user_id);
            if (a == 1) {
                return 1;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
        return -1;
    }
    /*
    删除收藏的音乐 传音乐id  与用户id
     */
    public int CollectionDel(Integer music_id,Integer user_id){
        try {
            int res=DB.executeUpdate("delete from usermusic where music_id= ?  and user_id= ? "
                    ,music_id
                    ,user_id);

            if (res == 1) {
                return 1;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
        return -1;
    }
}
